package com.wxg.study.easyexcel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.junit.Test;

import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.support.ExcelTypeEnum;

public class HelloWorld {

    @Test
    public void testExcel2003NoModel() {
        InputStream inputStream = getInputStream("loan1.xls");
        if (null == inputStream) {
        	throw new RuntimeException("找不到输入源！");
        }
        System.out.println("1111");
        try {
            // 解析每行结果在listener中处理
            ExcelListener listener = new ExcelListener();

            ExcelReader excelReader = new ExcelReader(inputStream, ExcelTypeEnum.XLS, null, listener);
            excelReader.read();
        } catch (Exception e) {

        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    
    @Test
    public void testExcel2007NoModel() {
        InputStream inputStream = getInputStream2007("loan1.xls");
        if (null == inputStream) {
        	throw new RuntimeException("找不到输入源！");
        }
        System.out.println("1111");
        try {
            // 解析每行结果在listener中处理
            ExcelListener listener = new ExcelListener();

            ExcelReader excelReader = new ExcelReader(inputStream, ExcelTypeEnum.XLSX, null, listener);
            excelReader.read();
        } catch (Exception e) {

        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    
    

	private InputStream getInputStream(String string) {
		String filename = null;
		filename = "D:\\供应商订单总数查询导出2018120423281854.xls";
		File file = new File(filename);
		try {
			return new FileInputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	private InputStream getInputStream2007(String string) {
		String filename = null;
		filename = "F:\\Downloads_old_02\\订单_订单管理_全部订单_20181107202212.xlsx";
		File file = new File(filename);
		try {
			return new FileInputStream(file);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		}
	}
}
